package io.github.xudaojie.boot.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.io.Serializable;
import java.util.List;

import io.github.xudaojie.boot.bean.Account;
import io.github.xudaojie.boot.mapper.AccountMapper;

@RestController
public class AccountController {

    @Autowired
    private AccountMapper accountMapper;

    @GetMapping("/accounts/{id}")
    public Account findById(@PathVariable Serializable id) {
        return accountMapper.selectById(id);
    }

    @PostMapping("/accounts")
    public Account insert(@RequestBody Account account) {
        accountMapper.insert(account);
        return account;
    }

    @PutMapping("/accounts")
    public int update(@RequestBody Account account) {
        return accountMapper.updateById(account);
    }

    @DeleteMapping("/accounts/{id}")
    public int delete(@PathVariable Serializable id) {
        return accountMapper.deleteById(id);
    }

    @GetMapping("/accounts/[{ids}]")
    public List<Account> batchIds(@PathVariable List<Serializable> ids) {
        return accountMapper.selectBatchIds(ids);
    }
}
